package com.clip.action;

import com.opensymphony.xwork2.ActionSupport;
@Deprecated
public class WeekViewAction extends ActionSupport{
//	@Autowired
//	private EventService eventService;
//	
//	private SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy_M_d");
//	public void getEventsByWeek(){
//		Calendar calendar=Calendar.getInstance();
//		HttpSession session=Struts2Utils.getSession();
//		User currentUser=(User) session.getAttribute(SessionAttributeKey.USER);
//		List events1=eventService.getEventsByWeek(this.year,this.numweek,calendar,currentUser);
//		
//		Map<String,Map> returnmap=organizeWeekViewMapAsXml(events1,currentUser);
//		Struts2Utils.renderXml(ToolsUtils.getDOM(returnmap));
//	}
//	
//	public void getThisWeek(){
//		Calendar calendar=Calendar.getInstance();
//		Map<String,Object> jsonMap = new HashMap<String, Object>();
//		jsonMap.put("year", calendar.get(Calendar.YEAR));
//		jsonMap.put("numweek", calendar.get(Calendar.WEEK_OF_YEAR));
//		jsonMap.put("maxweek", calendar.getActualMaximum(Calendar.WEEK_OF_YEAR));
//		jsonMap.put("dayofweek", calendar.get(Calendar.DAY_OF_WEEK));
//		for (int i = 1; i <=7; i++) {
//			calendar.set(Calendar.DAY_OF_WEEK, i);
//			jsonMap.put("day"+i, dateFormat.format(calendar.getTime()));
//		}
//		String jsonStr = com.clip.util.json.JSONObject.toJSONString(jsonMap);
//		Struts2Utils.renderText(jsonStr);
//	}
//	
//	public void getNextYear(){
//		Calendar calendar=Calendar.getInstance();
//		calendar.clear(Calendar.MILLISECOND);
//		calendar.clear(Calendar.SECOND);
//		calendar.clear(Calendar.MINUTE);
//		calendar.set(Calendar.HOUR_OF_DAY, 0);
//		calendar.set(Calendar.YEAR, year);
//		calendar.set(Calendar.WEEK_OF_YEAR,numweek);
//		calendar.add(Calendar.YEAR, 1);
//		Map<String,Object> jsonMap = new HashMap<String, Object>();
//		jsonMap.put("year", calendar.get(Calendar.YEAR));
//		jsonMap.put("numweek", calendar.get(Calendar.WEEK_OF_YEAR));
//		jsonMap.put("maxweek", calendar.getActualMaximum(Calendar.WEEK_OF_YEAR));
//		Calendar now=Calendar.getInstance();
//		if(now.get(Calendar.YEAR)==calendar.get(Calendar.YEAR)&&now.get(Calendar.WEEK_OF_YEAR)==calendar.get(Calendar.WEEK_OF_YEAR)){
//			jsonMap.put("dayofweek", calendar.get(Calendar.DAY_OF_WEEK));
//		}else{
//			jsonMap.put("dayofweek", 0);
//		}
//		for (int i = 1; i <=7; i++) {
//			calendar.set(Calendar.DAY_OF_WEEK, i);
//			jsonMap.put("day"+i, dateFormat.format(calendar.getTime()));
//		}
//		String jsonStr = com.clip.util.json.JSONObject.toJSONString(jsonMap);
//		Struts2Utils.renderText(jsonStr);
//	}
//	public void getNextWeek(){
//		Calendar calendar=Calendar.getInstance();
//		calendar.clear(Calendar.MILLISECOND);
//		calendar.clear(Calendar.SECOND);
//		calendar.clear(Calendar.MINUTE);
//		calendar.set(Calendar.HOUR_OF_DAY, 0);
//		calendar.set(Calendar.YEAR, year);
//		calendar.set(Calendar.WEEK_OF_YEAR,numweek);
//		calendar.add(Calendar.WEEK_OF_YEAR,1);
//		Map<String,Object> jsonMap = new HashMap<String, Object>();
//		jsonMap.put("year", calendar.get(Calendar.YEAR));
//		jsonMap.put("numweek", calendar.get(Calendar.WEEK_OF_YEAR));
//		jsonMap.put("maxweek", calendar.getActualMaximum(Calendar.WEEK_OF_YEAR));
//		Calendar now=Calendar.getInstance();
//		if(now.get(Calendar.YEAR)==calendar.get(Calendar.YEAR)&&now.get(Calendar.WEEK_OF_YEAR)==calendar.get(Calendar.WEEK_OF_YEAR)){
//			jsonMap.put("dayofweek", calendar.get(Calendar.DAY_OF_WEEK));
//		}else{
//			jsonMap.put("dayofweek", 0);
//		}
//		for (int i = 1; i <=7; i++) {
//			calendar.set(Calendar.DAY_OF_WEEK, i);
//			jsonMap.put("day"+i, dateFormat.format(calendar.getTime()));
//		}
//		String jsonStr = com.clip.util.json.JSONObject.toJSONString(jsonMap);
//		Struts2Utils.renderText(jsonStr);
//	}
//	public void getPrevWeek(){
//		Calendar calendar=Calendar.getInstance();
//		calendar.clear(Calendar.MILLISECOND);
//		calendar.clear(Calendar.SECOND);
//		calendar.clear(Calendar.MINUTE);
//		calendar.set(Calendar.HOUR_OF_DAY, 0);
//		calendar.set(Calendar.YEAR, year);
//		calendar.set(Calendar.WEEK_OF_YEAR,numweek);
//		calendar.add(Calendar.WEEK_OF_YEAR, -1);
//		Map<String,Object> jsonMap = new HashMap<String, Object>();
//		jsonMap.put("year", calendar.get(Calendar.YEAR));
//		jsonMap.put("numweek", calendar.get(Calendar.WEEK_OF_YEAR));
//		jsonMap.put("maxweek", calendar.getActualMaximum(Calendar.WEEK_OF_YEAR));
//		Calendar now=Calendar.getInstance();
//		if(now.get(Calendar.YEAR)==calendar.get(Calendar.YEAR)&&now.get(Calendar.WEEK_OF_YEAR)==calendar.get(Calendar.WEEK_OF_YEAR)){
//			jsonMap.put("dayofweek", calendar.get(Calendar.DAY_OF_WEEK));
//		}else{
//			jsonMap.put("dayofweek", 0);
//		}
//		for (int i = 1; i <=7; i++) {
//			calendar.set(Calendar.DAY_OF_WEEK, i);
//			jsonMap.put("day"+i, dateFormat.format(calendar.getTime()));
//		}
//		String jsonStr = com.clip.util.json.JSONObject.toJSONString(jsonMap);
//		Struts2Utils.renderText(jsonStr);
//	}
//	public void getPrevYear(){
//		Calendar calendar=Calendar.getInstance();
//		calendar.clear(Calendar.MILLISECOND);
//		calendar.clear(Calendar.SECOND);
//		calendar.clear(Calendar.MINUTE);
//		calendar.set(Calendar.HOUR_OF_DAY, 0);
//		calendar.set(Calendar.YEAR, year);
//		calendar.set(Calendar.WEEK_OF_YEAR,numweek);
//		calendar.add(Calendar.YEAR, -1);
//		Map<String,Object> jsonMap = new HashMap<String, Object>();
//		jsonMap.put("year", calendar.get(Calendar.YEAR));
//		jsonMap.put("numweek", calendar.get(Calendar.WEEK_OF_YEAR));
//		jsonMap.put("maxweek", calendar.getActualMaximum(Calendar.WEEK_OF_YEAR));
//		Calendar now=Calendar.getInstance();
//		if(now.get(Calendar.YEAR)==calendar.get(Calendar.YEAR)&&now.get(Calendar.WEEK_OF_YEAR)==calendar.get(Calendar.WEEK_OF_YEAR)){
//			jsonMap.put("dayofweek", calendar.get(Calendar.DAY_OF_WEEK));
//		}else{
//			jsonMap.put("dayofweek", 0);
//		}
//		for (int i = 1; i <=7; i++) {
//			calendar.set(Calendar.DAY_OF_WEEK, i);
//			jsonMap.put("day"+i, dateFormat.format(calendar.getTime()));
//		}
//		String jsonStr = com.clip.util.json.JSONObject.toJSONString(jsonMap);
//		Struts2Utils.renderText(jsonStr);
//	}
//	
//	public void getUserDefinedWeek(){
//		Calendar calendar=Calendar.getInstance();
//		calendar.clear(Calendar.MILLISECOND);
//		calendar.clear(Calendar.SECOND);
//		calendar.clear(Calendar.MINUTE);
//		calendar.set(Calendar.HOUR_OF_DAY, 0);
//		calendar.set(Calendar.YEAR, year);
//		calendar.set(Calendar.WEEK_OF_YEAR,numweek);
//		Map<String,Object> jsonMap = new HashMap<String, Object>();
//		jsonMap.put("year", calendar.get(Calendar.YEAR));
//		jsonMap.put("numweek", calendar.get(Calendar.WEEK_OF_YEAR));
//		jsonMap.put("maxweek", calendar.getActualMaximum(Calendar.WEEK_OF_YEAR));
//		
//		Calendar now=Calendar.getInstance();
//		if(now.get(Calendar.YEAR)==calendar.get(Calendar.YEAR)&&now.get(Calendar.WEEK_OF_YEAR)==calendar.get(Calendar.WEEK_OF_YEAR)){
//			jsonMap.put("dayofweek", calendar.get(Calendar.DAY_OF_WEEK));
//		}else{
//			jsonMap.put("dayofweek", 0);
//		}
//		for (int i = 1; i <=7; i++) {
//			calendar.set(Calendar.DAY_OF_WEEK, i);
//			jsonMap.put("day"+i, dateFormat.format(calendar.getTime()));
//		}
//		String jsonStr = com.clip.util.json.JSONObject.toJSONString(jsonMap);
//		Struts2Utils.renderText(jsonStr);
//	}
//	
//	public void acceptInvitedClip(){
//		HttpServletRequest request=Struts2Utils.getRequest();
//		User currentUser=(User) Struts2Utils.getSession().getAttribute(SessionAttributeKey.USER);
//		ClipEvent clipEvent=this.eventService.acceptInvitedClip(currentUser,eventid);
//		if(currentUser==null||currentUser.getId()<=0||clipEvent==null||clipEvent.getId()<=0)
//			Struts2Utils.renderText("");
//		Calendar firstDateOfWeek=Calendar.getInstance();
//		firstDateOfWeek.clear(Calendar.MILLISECOND);
//		firstDateOfWeek.clear(Calendar.SECOND);
//		firstDateOfWeek.clear(Calendar.MINUTE);
//		firstDateOfWeek.set(Calendar.HOUR_OF_DAY, 0);
//		firstDateOfWeek.set(Calendar.YEAR, this.year);
//		firstDateOfWeek.set(Calendar.WEEK_OF_YEAR,this.numweek);
//		firstDateOfWeek.add(Calendar.DAY_OF_MONTH, Calendar.SUNDAY-firstDateOfWeek.get(Calendar.DAY_OF_WEEK));
//		Calendar endDateOfWeek=(Calendar) firstDateOfWeek.clone();
//		endDateOfWeek.add(Calendar.DATE, 7);
//		Map reMap=new HashMap();
//		reMap.put("eventid", clipEvent.getId());
//		reMap.put("title", clipEvent.getTitle());
//		reMap.put("address", clipEvent.getAddress()==null||clipEvent.getAddress().length()==0?"":ToolsUtils.xmlCDATA(clipEvent.getAddress()));
//		String content=clipEvent.getContent();
//		reMap.put("content", content==null||content.length()==0?"":ToolsUtils.xmlCDATA(URLReplace.replace(content)));
//		reMap.put("eventtype", ClipEvent.eventtypeInt2Str(clipEvent.getEventtype()));
//		reMap.put("starttime", clipEvent.getBegintime());
//		reMap.put("endtime", clipEvent.getEndtime());
//		reMap.put("iswholeday", clipEvent.getIswholeday());
//		reMap.put("clocktime", clipEvent.getAlerttime());
////		reMap.put("deadlinetime", clipEvent.getDeadlinetime());
//		reMap.put("reliedclip", clipEvent.getReliedclip());
//		reMap.put("isvip", clipEvent.getIsvip());
//		reMap.put("processstatus", clipEvent.getProcessstatus());
////		List<String> names=this.eventService.getPublishname(clipEvent,currentUser);
////		if(names.size()>0){
////			reMap.put("publishname", names.get(0));
////			if(names.size()>1)
////				reMap.put("forwardname", names.get(1));
////		}
//		if(isBelongPassage(firstDateOfWeek,endDateOfWeek,clipEvent)){
//			reMap.put("iscrtweek", 1);
//			int startday=getStartDayOfWeek(clipEvent.getBegintime(),firstDateOfWeek);
//			int endday=getEndDayOfWeek(clipEvent.getIswholeday(), clipEvent.getEndtime(),endDateOfWeek);
//			reMap.put("startday",startday);
//			reMap.put("endday",endday<0?startday:endday);
//		}else{
//			reMap.put("iscrtweek", 0);
//		}
//		Struts2Utils.renderXml(ToolsUtils.getDOM(reMap));
//	}
//	
//	private boolean isBelongPassage(Calendar passageBegin,Calendar passageEnd,ClipEvent clipEvent){
//		if((clipEvent.getBegintime()<=passageBegin.getTimeInMillis() && clipEvent.getEndtime()>=passageBegin.getTimeInMillis())
//				||(clipEvent.getBegintime()>passageBegin.getTimeInMillis()&&clipEvent.getBegintime()<passageEnd.getTimeInMillis())){
//			return true;
//		}else{
//			return false;
//		}
//	}
//	
//	private Map<String, Map> organizeWeekViewMapAsXml(List list,
//			User user) {
//		Map<String, Map> returnMap=new LinkedHashMap<String, Map>();
////		Set sets=map.keySet();
//		Calendar now=Calendar.getInstance();
//		Calendar firstDateOfWeek=Calendar.getInstance();
//		firstDateOfWeek.clear(Calendar.MILLISECOND);
//		firstDateOfWeek.clear(Calendar.SECOND);
//		firstDateOfWeek.clear(Calendar.MINUTE);
//		firstDateOfWeek.set(Calendar.HOUR_OF_DAY, 0);
//		firstDateOfWeek.set(Calendar.YEAR, year);
//		firstDateOfWeek.set(Calendar.WEEK_OF_YEAR,numweek);
//		firstDateOfWeek.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
//		Calendar endDateOfWeek=(Calendar) firstDateOfWeek.clone();
//		endDateOfWeek.add(Calendar.DAY_OF_MONTH, 7);
//		for (Object object : list) {
//			EventForView eventforview=(EventForView) object;
//			Map<String,Object> temp2=new HashMap<String,Object>();
//			temp2.put("eventid", eventforview.getEventid());
////			temp2.put("starthour", eventforview.getStarthour().toString());
////			temp2.put("endhour", eventforview.getEndhour().toString());
//			temp2.put("isClocked", ""+eventforview.isClocked());
//			temp2.put("isThisMonth", ""+eventforview.isThisMonth());
//			temp2.put("eventtype", eventforview.getEventtype());
//			temp2.put("starttime", eventforview.getStarttime().toString());
//			temp2.put("endtime", eventforview.getEndtime().toString());
//			temp2.put("iswholeday", eventforview.getIswholeday().toString());
//			temp2.put("content", eventforview.getContent());
//			temp2.put("clocktime", eventforview.getClocktime()==null?"":eventforview.getClocktime());
//			temp2.put("address", eventforview.getAddress());
//			temp2.put("title", eventforview.getTitle());
//			int startday=getStartDayOfWeek(eventforview.getStarttime(),firstDateOfWeek);
//			temp2.put("startday", getStartDayOfWeek(eventforview.getStarttime(),firstDateOfWeek));
//			int endday=getEndDayOfWeek(eventforview.getIswholeday(),eventforview.getEndtime(),endDateOfWeek);
//			temp2.put("endday", endday<0?startday:endday);
//			temp2.put("deadlinetime", eventforview.getDeadlinetime().toString());
//			temp2.put("reliedclip", eventforview.getReliedclip().toString());
//			temp2.put("isvip", eventforview.getIsvip().toString());
//			temp2.put("istodayortommorrow", ""+eventforview.isTodayOrTommorrow());
//			temp2.put("processstatus", eventforview.getProcessstatus().toString());
//			temp2.put("publishname", eventforview.getPublishname());
//			temp2.put("forwardname", eventforview.getForwardname());
//			temp2.put("puid", eventforview.getPuid());
//			temp2.put("fuid", eventforview.getFuid());
//			temp2.put("cliptype", eventforview.getCliptype());
//			//temp2.put("date", firstDateOfWeek.getTimeInMillis());
//			returnMap.put("EventForView id="+eventforview.getEventid(), temp2);
//		}
//		
//		
//		return returnMap;
//	}
//	
//	private Integer getStartDayOfWeek(Long starttime,Calendar firstDateOfWeek){
//		if(starttime<firstDateOfWeek.getTimeInMillis()){
//			return 1;
//		}else{
//			Calendar calendar=Calendar.getInstance();
//			calendar.setTimeInMillis(starttime);
//			return calendar.get(Calendar.DAY_OF_WEEK);
//		}
//	}
//	
//	/**
//	 * @param clipevent
//	 * @param lastDateOfWeek
//	 * @return -1 表示同开始日子同一天，单日事件
//	 */
//	private Integer getEndDayOfWeek(int iswholeday,long endtime,Calendar lastDateOfWeek){
//		if(iswholeday==1){
//			return -1;
//		}else{
//			if(endtime>=lastDateOfWeek.getTimeInMillis()){
//				return 7;
//			}else{
//				Calendar calendar=Calendar.getInstance();
//				calendar.setTimeInMillis(endtime);
//				return calendar.get(Calendar.DAY_OF_WEEK);
//			}
//		}
//	}
//	private int year;
//	private int numweek;
//	private int eventid;
//	public int getYear() {
//		return year;
//	}
//	public void setYear(int year) {
//		this.year = year;
//	}
//	public int getNumweek() {
//		return numweek;
//	}
//	public void setNumweek(int numweek) {
//		this.numweek = numweek;
//	}
//	public int getEventid() {
//		return eventid;
//	}
//
//	public void setEventid(int eventid) {
//		this.eventid = eventid;
//	}
//	
}
